<?php
@require_once("config.php");
$goodsid=$_GET["goodsid"];
$usertel=$_GET["usertel"];
$price=$_GET["price"];
$goodscolor=$_GET["goodsColor"];
$dingzhi=$_GET["dingzhi"];
$goodsname=$_GET["goodsname"];

$str1="select count(*) from shoppinginfo where usertel=$usertel and goodsid=$goodsid";
$result1=mysql_query($str1);
$obj1=mysql_fetch_array($result1);

if($obj1[0]>0){
    $str2="select * from shoppinginfo where usertel=$usertel and goodsid=$goodsid";
    $result2=mysql_query($str2);
    $list2=array();
    while($item2=mysql_fetch_array($result2)){
        $temp2=array();
        $temp2["goodscolor"]=$item2["goodscolor"];
        $temp2["price"]=$item2["price"];
        $temp2["dingzhi"]=$item2["dingzhi"];
        $temp2["num"]=$item2["num"];
        $list2[]=$temp2;
    }
    // $colorsList=array();
    $flag=true;
    // echo $goodscolor;
    foreach($list2 as $value){
        // echo $value["goodscolor"];
        if($goodscolor==$value["goodscolor"]){
            $flag;
            break;
        }else{
            $flag=false;
           
        }     
    }
    if($flag){
        // echo "1111";
        foreach($list2 as $value){
            // echo $value["dingzhi"];
            if($dingzhi==$value["dingzhi"]){
                $flag=true;
                $number=$value["num"];
                break;   
            }else{
                $flag=false;
            }
        }
        if($flag){
            // echo "1111";
            $number=$number+1;
            // echo $number;
            $str3="update shoppinginfo set num=$number where goodsid=$goodsid and usertel=$usertel and goodscolor='$goodscolor' and dingzhi='$dingzhi'";
            mysql_query($str3);
            $count=mysql_affected_rows();
            echo $count;
        }else{
            // echo "2222";
            $str="insert into shoppinginfo(goodsid,usertel,price,goodscolor,dingzhi,num,goodsname)  values($goodsid,$usertel,$price,'$goodscolor','$dingzhi',1,'$goodsname')";
            $result=mysql_query($str);
            $count=mysql_affected_rows();
            echo $count;
        }
    }else{
        // echo "2222";
        $str="insert into shoppinginfo(goodsid,usertel,price,goodscolor,dingzhi,num,goodsname)  values($goodsid,$usertel,$price,'$goodscolor','$dingzhi',1,'$goodsname')";
        $result=mysql_query($str);
        $count=mysql_affected_rows();
        echo $count; 
    }
    
    
}else{
    $str="insert into shoppinginfo(goodsid,usertel,price,goodscolor,dingzhi,num,goodsname)  values($goodsid,$usertel,$price,'$goodscolor','$dingzhi',1,'$goodsname')";
    $result=mysql_query($str);
    $count=mysql_affected_rows();
    echo $count;
}

?>